package service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import model.DAO;
import model.DBUtil;
import model.beans.Topic;

public class Service {
		/**
		 * @version 将话题存入数据库中 
		 * @author flyingocean.huwei
		 * @param t 想要存入的话题
		 * @return 如果成功存入返回true 否则返回false
		 * @throws SQLException 
		 */
		
		public boolean addTopic(Topic t) throws SQLException {
			if(t==null) {
				return false;
			}
			DAO.addTopic(t);
			return true;
		}
		
		/**
		 * @author flyingocean.huwei
		 * @version 删除指定id的话题  
		 * @throws SQLException
		 * @param id 指定的要删除话题的id
		 * @return  boolean 如果成功删除返回true, 或因话题不存在等原因则返回false
		 */
		public  boolean deleteTopicById(String id) throws SQLException {
			if(DAO.queryTopicByTopicId(id)==null) {
				return false;
			}else {
				DAO.deleteTopicById(id);
				return true;
			}
		}
		
		/**
		 * @author flyingocean.huwei
		 * @version 获得数据库中所有话题
		 * @throws SQLException
		 * @return  List<Topic> Arraylist<Topic>
		 */
		public  List<Topic> queryAllTopic() throws SQLException {
			return DAO.queryAllTopic();
		}
		
		/**
		 * @author flyingocean.huwei
		 * @version 根据qq号查询话题 
		 * @throws SQLException
		 * @return List<Topic> Arraylist<Topic>
		 */
		public  List<Topic> queryTopicByQQ(String qq) throws SQLException {
			return DAO.queryTopicByQQ(qq);
		}
		
		/**
		 * @author flyingocean.huwei
		 * @param 所要查询的id
		 * @version 根据id查询话题
		 * @throws SQLException
		 * @return 如果查询成功返回topic对象,否则返回null
		 */
		public  Topic queryTopicByTopicId(String TopicId) throws SQLException {
			return DAO.queryTopicByTopicId(TopicId);
		}
}
